package com.mdd.admin.controller.order;

import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.IMansionService;
import com.mdd.admin.validate.order.MansionCreateValidate;
import com.mdd.admin.validate.order.MansionSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.validate.order.MansionUpdateValidate;
import com.mdd.admin.vo.order.MansionVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.enums.HttpEnum;
import com.mdd.common.validator.annotation.IDMust;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 大厦管理
 * @author shenjian
 * @createTime 2023年02月05日 23:20:00
 */
@RestController
@RequestMapping("api/mansion")
@CrossOrigin
public class MansionController {


    @Resource
    IMansionService iMansionService;

    /**
     * 大厦列表
     *
     * @author shenjian
     * @param pageValidate 分页参数
     * @param searchValidate 搜索参数
     * @return AjaxResult<PageResult<MansionVo>>
     */
    @Log(title = "大厦列表")
    @GetMapping("/list")
    public AjaxResult<PageResult<MansionVo>> list(@Validated PageValidate pageValidate,
                                                  @Validated MansionSearchValidate searchValidate) {
        PageResult<MansionVo> list = iMansionService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @Log(title = "查询大厦详情")
    @GetMapping("/detail")
    public AjaxResult<MansionVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        return AjaxResult.success(iMansionService.detail(id));
    }

    @Log(title = "新增大厦")
    @PostMapping("/add")
    public AjaxResult<?> add(@Validated @RequestBody MansionCreateValidate createValidate) {
        iMansionService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "更新大厦")
    @PostMapping("/edit")
    public AjaxResult<?> update(@Validated @RequestBody MansionUpdateValidate updateValidate) {
        iMansionService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "删除大厦")
    @GetMapping("/del")
    public AjaxResult<?> delete(@Validated @IDMust() @RequestParam("id") Integer id) {
        iMansionService.del(id);
        return AjaxResult.success();
    }

    @Log(title = "创建大厦编号")
    @GetMapping("/create_sn")
    public AjaxResult<String> createSn() {
        return AjaxResult.success(HttpEnum.SUCCESS.getCode(), HttpEnum.SUCCESS.getMsg(), iMansionService.createSn());
    }
}
